import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: "/", redirect: 'login' },
    { path: "/login", name: 'login', meta: { title: "登录界面" }, component: () => import("@/views/Login.vue") },
    { path: "/registry", name: 'registry', meta: { title: "注册界面" }, component: () => import("@/views/Registry.vue") },
    {
      path: "/home", name: "home", meta: { title: "首页" }, component: () => import("@/views/Home.vue"), children: [
        { path: "employee", name: "employee", meta: { title: "员工页" }, component: () => import("@/views/Employee.vue") }
      ]
    },
    { path: "/404", name: "404", meta: { title: "Not Found" }, component: () => import("@/views/404.vue") },
    { path: "/:pathMath(.*)*", redirect: '404' },
  ],
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

export default router
